import axios from 'axios'
import { useUserInfoStore } from '@/stores/modules/userInfo'
import pinia from '@/stores'

const http = axios.create({
  baseURL: '/qiantai',
  timeout: 5000
})

http.interceptors.request.use(
  function (config) {
    config.headers = {
      token: useUserInfoStore(pinia).token
    }
    return config
  },
  function (error) {
    return Promise.reject(error)
  }
)

http.interceptors.response.use(
  function (response) {
    return response.data.data
  },
  function (error) {
    return Promise.reject(error)
  }
)

export default http
